package cmd

import (
	"fmt"
	"os"

	// "github.com/spf13/cobra"
	cobra "hw05/myCobra"
)

var name string
var age int

var rootCmd = &cobra.Command{
	Use:   "test",
	Short: "a testing of command",
	Long:  `reference: https://github.com/spf13/cobra`,
	Run: func(cmd *cobra.Command, args []string) {
		// 执行程序
		// fmt.Println("Hello world")
		if name != "" && age != 0 {
			fmt.Print("Hello ", name, ", a ", age, " years old student")
		}
	},
}

func init() {
	// 命令的层级关系
	rootCmd.AddCommand(timeCmd)
	rootCmd.PersistentFlags().StringVarP(&name, "name", "n", "", "person's name")
	rootCmd.PersistentFlags().IntVarP(&age, "age", "a", 0, "person's age")
}

func Execute() {

	if err := rootCmd.Execute(); err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}
}
